<template>
    <rx-layout>
        <template v-slot:header>
            <rx-filters :isBpmClient="false"
                        :isMyBpm="isMyBpmClient"
                        :readType="readType"
                        :readKey="readKey"
                        :treePrefix="treePrefix"
                        screenName="SUBJECT"
                        :keyname="getTreeCatByList.key" :namelit="getTreeCatByList.name"
                        @loadListByParams="loadListByParams"
                        :appId="appId"
                        :placeholder="i18n('EnterName','请输入待办名称')"></rx-filters>
        </template>
        <template v-slot:center>
            <rx-grid ref="rxGrid" :queryParam="queryParam" :url="'/api-bpm/bpm/core/bpmTask/myTasks'">
                <template v-slot:center="{record}">
                    <view class="rx-center" @click="bpmDetails(record)">
                        <view class="rx-html" v-if="getStatusHtml(record.status)"
                              v-html="getStatusHtml(record.status)"></view>
                        <view class="rx-createTime">
                            <my-icon style="color: rgba(66, 133, 244, 1);font-size: 1.2rem"
                                     type="icon-linetime"></my-icon>
                            <view class="rx-createTime-name">{{ record.createTime }}</view>
                        </view>
                        <view class="rx-top">
                            <view class="rx-icon-le"><view class="rx-icon_liucheng"><my-icon type="icon-Vue3jpaas-icon_liucheng"></my-icon></view></view>
                            <view class="rx-subject">{{ record.subject }}</view>
                        </view>
                        <view v-if="record.formJson">
                            <view class="rx-formJson" v-for="(row,index) in JSON.parse(record.formJson)" :key="index">
                                <span class="rx-formJson-name">{{ row.label }}:</span>
                                <span>{{ row.val }}</span>
                            </view>
                        </view>
                        <view class="rx-bottom">
                            <view class="rx-bottom-list">
                                <span class="rx-bottom-span">{{ i18n('process', '审批环节') }}:</span>
                                <span class="rx-bottom-name">{{ $i18(record.name) }}</span>
                            </view>
                        </view>
                    </view>
                </template>
            </rx-grid>
        </template>
    </rx-layout>
</template>

<script>
import RxGrid from '@/components/RxGrid'
import RxLayout from '@/components/RxLayout'
import RxFilters from '@/components/RxFilters'
import instAndTaskShareApi from "@/api/instAndTaskShareApi";
import getStatusHtml from '@/common/getStatusHtml.js'

export default {
    name: "RxMyTracked",
    components: {RxGrid, RxLayout, RxFilters},
    mixins: [getStatusHtml],
    data() {
        return {
            isMyBpmClient: true,
            readType: "task",
            readKey: "task.read",
            treePrefix: 'v.',
            isInit: true,
            getTreeCatByList: '',
            queryParam: {},//筛选参数
            appId: "",//应用id
        }
    },
    onLoad(option) {
        let params = {}
        if (option && option.params) {
            params = JSON.parse(option.params)
        }
        if (params.defId) {
            this.$set(this.queryParam, 'Q_v.DEF_ID__S_EQ', params.defId)
        }
        if (params.appId) {
            this.appId = params.appId
        }
        this.getTreeCatByKey()
    },
    onShow(){
        if(this.$refs.rxGrid){
            this.$refs.rxGrid.getInit(true, true);
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "bpmLang", key);
        },
        getTreeCatByKey() {
            instAndTaskShareApi.getTreeCatByKey().then(ret => {
                this.getTreeCatByList = ret;
            })
        },
        //筛选
        loadListByParams(params) {
            this.queryParam = params
        },
        bpmDetails(obj) {
            if ("BATCH_PARENT" === obj.batchTaskType) {
                let data = {
                    taskId: obj.taskId,
                    instId: obj.instId,
                }
                let url = '/pages/RxProcessManagement/RxMyTasks/BatchTaskDetail';
                url = url + '?data=' + JSON.stringify(data)
                uni.navigateTo({url: url})
                return;
            }

            let params = {
                taskId: obj.taskId,
                instId: obj.instId,
                routerName: 'openDoc',
                action: 'edit'
            }
            let mobileAppId = uni.getStorageSync("mobileAppId");
            let appId = ''
            if (obj.appId) {
                appId = obj.appId ? obj.appId : mobileAppId
            }
            uni.navigateTo({
                url: '/views/modules/bpm/OpenDoc?params=' + JSON.stringify(params) + "&appId=" + appId
            })
        }
    }
}
</script>

<style scoped>
@import "../RxProcessManagement.css";
</style>
